//
//  CCController.h
//  CommandCenter08
//
//  Created by Matt Roman on 7/1/08.
//  Copyright 2008 University of Oklahoma. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "Waypoint.h"
#import "OGLmap.h"
#import	"Rover.h"
#import "joystick.h"
#import "definitions.h"
#import	"NetClient.h"
#import "meterView.h"
#import "OGLsensor.h"
#import "roverKonstants.h"

#import <mach/mach_port.h>
#import <mach/mach_interface.h>
#import <mach/mach_init.h>

#import <IOKit/pwr_mgt/IOPMLib.h>
#import <IOKit/IOMessage.h>

typedef struct _PowerNote {
	io_connect_t			rootPowerPort;
	IONotificationPortRef	notifyPortRef;
	io_object_t				notifierObj;
	void*					refCon;
} PowerNote;

@interface CCController : NSObject {
	///////////////////////////////////////////////////
	// windows and panels
	IBOutlet NSWindow		*mainWindow;
	IBOutlet NSPanel		*wpListPanel;
	IBOutlet NSPanel		*wpEditPanel;
	IBOutlet NSPanel		*joyPanel;
	IBOutlet NSPanel		*RSPosPanel;
	IBOutlet NSPanel		*NetworkPanel;
	IBOutlet NSPanel		*RoverPanel;
	IBOutlet NSPanel		*SensorPanel;
	IBOutlet NSPanel		*SensorHeightsPanel;
	IBOutlet roverKonstants	*KonstantsPanel;
	IBOutlet NSPanel		*helpPanel;
	IBOutlet NSPanel		*qscPanel;
	
	// table view control and waypoint list
	IBOutlet NSTableView	*WayPointTable;
	NSMutableArray			*WayPointList;
	IBOutlet NSButton		*deleteWPButton;
	IBOutlet NSTextField	*currentWaypoint;
	
	// Waypoint editor popup menu
	Waypoint				*EditTempWaypoint;
	IBOutlet NSTextField	*WEPTime;
	IBOutlet NSTextField	*WEPdistance;
	IBOutlet NSTextField	*WEPXcord;
	IBOutlet NSTextField	*WEPYcord;
	IBOutlet NSButton		*WEPicon;
	IBOutlet NSPopUpButton	*WEPsciencePopUp;
	IBOutlet NSTextView		*WEPnotes;
	
	// Rover set position panel
	IBOutlet NSTextField	*RSlatitude;
	IBOutlet NSTextField	*RSlongitude;
	IBOutlet NSButton		*RSLatLonButton;
	IBOutlet NSButton		*RSGPSButton;
	IBOutlet NSTextField	*RSXpos;
	IBOutlet NSTextField	*RSYpos;
	IBOutlet NSButton		*RSGotoButton;
	IBOutlet NSTextField	*RSGotoWaypoint;
	IBOutlet NSTextField	*RSPan,*RSTilt;
	
	// openGL map view port
	IBOutlet OGLmap			*mapViewPort;
	double					WorldRadius;
	LatLonCoord				homeCoords;
	
	// rover
	Rover					*sr2;
	// joystick
	IBOutlet joystick		*gamePad;
	
	// configuration file
	NSFileHandle			*configFile;
	NSString				*configFileName;
	
	// Network variables
	NetClient				*clientSock;
	IBOutlet NSTextView		*textOut;
	IBOutlet NSTextField	*hostAddressField;
	IBOutlet NSTextField	*sendCommField;
	IBOutlet NSButton		*netConnectButton;
	BOOL					haveSensorsSetup;
	BOOL					incommingSensorSetup;
	BOOL					incommingSensorUpdate;
	BOOL					incommingKonstants;
	BOOL					incommingWaypoint;
	BOOL					incommingWPList;
	
	// rover properties view panel
	IBOutlet meterView		*electricMeterView;
	IBOutlet NSTextField	*roverX,*roverY;
	IBOutlet NSTextField	*roverSpeedL,*roverSpeedR;
	IBOutlet NSTextField	*roverState,*roverError;
	IBOutlet NSTextField	*roverLat,*roverLon;
	IBOutlet NSTextField	*roverPitch,*roverRoll;
	IBOutlet NSTextField	*roverHeading;
	IBOutlet NSTextField	*roverTurnDirection;
	IBOutlet NSTextField	*roverXBCtime;
	
	// sensor view panel
	IBOutlet OGLsensor		*compassView;
	IBOutlet OGLsensor		*bodyLaserView;
	IBOutlet OGLsensor		*panelLaserView;
	IBOutlet OGLsensor		*profileLaserView;
	IBOutlet OGLsensor		*panelHeightView;
	IBOutlet OGLsensor		*profileHeightView;
	
	BOOL					simSwitch;
}

- (IBAction)deleteWaypoint:(id)sender;
- (IBAction)addWaypoint:(id)sender;
- (IBAction)editScience:(id)sender;
- (IBAction)editWaypointState:(id)sender;
- (IBAction)sendPlan:(id)sender;
- (IBAction)calibrateMap:(id)sender;
- (IBAction)JoystickOn:(id)sender;
- (IBAction)openFile:(id)sender;
- (IBAction)setRoverPosition:(id)sender;
- (IBAction)saveFile:(id)sender;
- (IBAction)setLatLonPosition:(id)sender;
- (IBAction)setPosGPS:(id)sender;
- (IBAction)setPosXY:(id)sender;
- (IBAction)setGotoWaypoint:(id)sender;
- (IBAction)setAtCursorPoint:(id)sender;
- (IBAction)setPanTilt:(id)sender;
- (IBAction)snapImage:(id)sender;
- (IBAction)viewWaypointList:(id)sender;
- (IBAction)reverseWaypointList:(id)sender;
- (IBAction)viewRoverPanel:(id)sender;
- (IBAction)viewNetworkPanel:(id)sender;
- (IBAction)viewSensorPanel:(id)sender;
- (IBAction)viewMapWindow:(id)sender;
- (IBAction)viewSensorHeightsPanel:(id)sender;
- (IBAction)viewRoverKonstants:(id)sender;
- (IBAction)viewHelpPanel:(id)sender;
- (IBAction)viewQuitSavePanel:(id)sender;
- (IBAction)stopRover:(id)sender;
- (IBAction)networkConnectButton:(id)sender;
- (IBAction)sendCommandButton:(id)sender;
- (IBAction)saveAndQuit:(id)sender;
- (IBAction)quitButton:(id)sender;
- (IBAction)cancelButton:(id)sender;

- (void)initializeWPTable;
- (void)updateUI;
- (void)editWaypoint;
- (void)doneEditingWaypoint;
- (void)sendPosition:(Point3D)pt;
- (void)sendGoToWaypoint:(int)wp;
- (void)openCC8:(NSString*)filename;
- (void)importKML:(NSString*)filename;
- (void)importTerrain:(NSString*)filename;
- (void)initPowerPort;
- (void)unregisterPowerPort;
- (void)writeConfigFile;


- (Point3D)LatLonConvertFrom:(LatLonCoord)ll1 to:(LatLonCoord)ll2;
- (LatLonCoord)LatLonCoordFrom:(LatLonCoord)ll1 toPoint:(Point3D)pp2;
- (void)setCurrentWorldRadius:(LatLonCoord)llcord;
@end
